<?php
namespace app\web\admin;

use app\common\builder\ZBuilder;
use app\web\model\Comment as myModel;
use app\web\model\Shop;
use app\web\model\Project;
use app\web\model\Technician;

/**
 * 评论（后台）
 * @package
 */
class Comment extends Base 
{
    private $status = ['禁用','启用'];
    public function index() 
    {
        $map = $this->getMap();
 
        foreach ($map as $key => $value) {
            if($value[0] == 'shop_id') $map[$key][0] = 'a.shop_id';
            if($value[0] == 'project_id') $map[$key][0] = 'a.project_id';
            if($value[0] == 'technician_id') $map[$key][0] = 'a.technician_id';
            if($value[0] == 'create_time'){
                $map[$key][0] = 'a.create_time';
                $map[$key][2][0] = strtotime($value[2][0]);
                $map[$key][2][1] = strtotime($value[2][1]);
            }
        }
        $data_list = myModel::alias('a')
                            ->where($map)
                            ->field('a.id,a.user_id,a.star,a.content,a.images as images1,a.status,a.create_time,b.nickName,c.shop_name as shop_id,d.order_no,e.real_name as technician_id,f.project_name as project_id')
                            ->leftjoin('order d','d.id=a.order_id')
                            ->leftjoin('user b','b.id=a.user_id')
                            ->leftjoin('technician e','e.id=a.technician_id')
                            ->leftjoin('project f','f.id=a.project_id')
                            ->leftjoin('shop c','c.id=a.shop_id')
                            ->order($this->getOrder("a.id desc"))
                            ->paginate()->each(function($item,$k){
                                return $this->tableImg($item,$k,'images1');
                            });
        $addColumns = [
                ['order_no','订单编号'],
                ['technician_id','技师姓名'],
                ['project_id','项目名称'],
                ['shop_id','店铺名称'],
                ['nickName','用户昵称'],
                ['star','星级评分'],
                ['content','评论类容'],
                ['images1','评论图片'],
                ['status','状态','switch'],
                ['create_time','评论时间'],
            ];
        return ZBuilder::make('table')
            ->setTableName('comment')
            ->addColumns($addColumns)
            ->addTimeFilter('create_time')
            ->addTopButtons('enable,disable')
            ->addOrder('star')
            ->addFilterList('status',['禁用','启用'])
            ->setRowList($data_list)
            ->setColumnWidth('create_time',150)
            ->addFilterList('shop_id',Shop::getSelectAll())
            ->addFilterList('project_id',Project::getSelectAll('check_status=1'))
            ->addFilterList('technician_id',Technician::getSelectAll('check_status=1','real_name'))
            ->fetch();   
    }
}